package com.blog.dao.frontpage;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.blog.dao.conn.BaseDao;
import com.blog.dao.conn.ParamSet;
import com.blog.dao.conn.RowDatas;
import com.blog.entity.SupportEntity;

public class SupportDao extends BaseDao{
	private RowDatas<SupportEntity> support = new RowDatas<SupportEntity>() {

		@Override
		public SupportEntity getRowData(ResultSet rs) throws SQLException {
			SupportEntity se = new SupportEntity();
			se.setDiscuss_id(rs.getInt("discuss_id"));
			return se;
		}
	};
	/**
	 * 根据文章id和点赞人id修改点赞数
	 */
	public int updateSupportNumber(int articleid) {
		int row = 0;
		String sql = "update tb_article set article_supportnumber =article_supportnumber+1 where article_id =?";
		row = updateExecuted(sql, new ParamSet(articleid));
		return row;
	}
	
	/**
	 * 根据点赞向数据库插入一条数据
	 */
	public int insertSupportNumber(int supportid, int articleid) {
		int row = 0;
		String sql = "INSERT INTO tb_support (article_id,discuss_id) VALUES(?,?)";
		row = updateExecuted(sql, new ParamSet(supportid,articleid));
		return row;
	}
	
	/**
	 * 根据查询文章id判断该用户是否存在
	 */
	public SupportEntity querySupportNumber(int articleid) {
		String sql = "select discuss_id from tb_support where article_id = ?";
		return query(sql,new ParamSet(articleid),support);
	}

}
